<?php 
global $_W,$_GPC;

$mobile = trim($_GPC['mobile']);

$table = "imeepos_runner3_setting";
$code = 'sms_set';

$sql = "SELECT * FROM ".tablename($table)." WHERE uniacid = :uniacid AND code = :code";
$params = array(':uniacid'=>$_W['uniacid'],':code'=>$code);
$setting = pdo_fetch($sql,$params);

$item = iunserializer($setting['value']);

if(!empty($mobile)){
	$code = random(4,true);
	$content = "欢迎您".$user['nickname'].",您的验证码是:".$code;
	
	$data = array();
	$data['uniacid'] = $_W['uniacid'];
	$data['openid'] = $_W['openid'];
	$data['time'] = time();
	$data['code'] = $code;
	$data['mobile'] = $mobile;
	$data['content'] = $content;
	pdo_insert('imeepos_runner3_code',$data);
	$codeid = pdo_insertid();

	include IA_ROOT."/addons/imeepos_runner/inc/mobile/TopSdk.php";
	
	$c = new TopClient();
	$c->appkey = $item['appkey'];//appkey
	$c->secretKey = $item['appsecret'];//appsecret
	$req = new AlibabaAliqinFcSmsNumSendRequest;
	$req->setExtend("123456");
	$req->setSmsType("normal");
	$req->setSmsFreeSignName($item['signname']);//身份验证签名 身份验证
	
	$json = json_encode(array("code"=>$data['code'],'product'=>'跑腿'));
	$req->setSmsParam($json);
	$req->setRecNum($mobile);
	
	$req->setSmsTemplateCode($item['moban_num']);//  身份验证 模板号 SMS_6290144
	
	$return = $c->execute($req);
	
    $result = array();
    $result['codeid'] = $codeid;
    $result['result'] = $return;
    die(json_encode($result));
}
